有没有更好的方法在文本块中添加换行符而不是在每个项目之后添加
?(Is there a better way to add line-breaks in a block of text than just putting
after every item?)
我有一个很大的项目列表,其格式如下:
list item <br> list item <br> list item <br> list item <br> list item <br> list item <br>
等等
目前,我已经通过在每个项目之后添加
br
来让他们工作,但它有点混乱。 是否有一些我可以使用的CSS或HTML会在每个项目后自动断行? 它们目前都在p
标签内。I have a big list of items that are formatted like so:
list item <br> list item <br> list item <br> list item <br> list item <br> list item <br>
etc.
Currently, I've got them to work by putting a
br
after every item, but it's kinda messy. Is there some CSS or HTML that I can use that will automatically break the line after each item? They are all currently inside ap
tag.
原文:https://stackoverflow.com/questions/35588559
满意答案
在您的示例中,
map
和forEach
之间的本质区别在于forEach
对原始数组元素进行操作,而map
显式返回一个新的数组。使用
forEach
您将对原始数组中的每个元素进行一些操作(可选择更改)。forEach
方法运行您为每个元素提供的函数,但不返回任何内容(undefined
)。 另一方面,map
遍历数组,对每个元素应用一个函数,并将结果作为新的数组发出 。
forEach
的“副作用”是原来的数组正在改变。 使用map
“无副作用”意味着,在惯用语中,原始数组元素不改变; 新数组是原始数组中每个元素的一对一映射 - 映射变换是您提供的函数。没有数据库涉及的事实并不意味着您不必对数据结构进行操作,毕竟这是数据结构中任何语言的编程之一。 对于你最后一个问题,你的数组不仅可以包含数字,而且可以包含对象,字符串,函数等。
The essential difference between
map
andforEach
in your example is thatforEach
operates on the original array elements, whereasmap
explicitly returns a new array as a result.With
forEach
you are taking some action with -- and optionally changing -- each element in the original array. TheforEach
method runs the function you provide for each element, but returns nothing (undefined
). On the other hand,map
walks through the array, applies a function to each element, and emits the result as a new array.The "side effect" with
forEach
is that the original array is being changed. "No side effect" withmap
means that, in idiomatic usage, the original array elements are not changed; the new array is a one-to-one mapping of each element in the original array -- the mapping transform being your provided function.The fact that there's no database involved does not mean that you won't have to operate on data structures, which, after all, is one of the essences of programming in any language. As for your last question, your array can contain not only numbers, but objects, strings, functions, etc.
相关问答
更多javascript - 在Map.prototype.forEach()中获取索引(javascript - get index in Map.prototype.forEach())
[.forEach.call()在JavaScript中做什么?(What does [].forEach.call() do in JavaScript?)
javascript forEach方法有什么用途(该地图无法做什么)?(what use does the javascript forEach method have (that map can't do)?)
如何停止Javascript forEach?(how to stop Javascript forEach? [duplicate])
Javascript递归,foreach循环不会退出?(Javascript recursion, foreach loop won't exit?)
使用forEach方法更改项目的属性(javascript)(Change Properties of Items using a forEach Method (javascript))
JavaScript - ForEach(JavaScript - ForEach)
想要通过使用Javascripts map,reduce,foreach,filter方法来实现功能(Want to achieve functionality by using Javascripts map,reduce,foreach,filter methods)
For循环,map和forEach Javascript(For-loop, map and forEach Javascript)
javascript forEach范围(javascript forEach scope)
相关文章
更多Becoming a data scientist
Create a Bootable MicroSD Card
Securing Solr on Tomcat access using a user account
按钮样式
Solr: a custom Search RequestHandler
A Great List of Windows Tools
Become a Master Designer: Rule Three: Contrast, Contrast, Contrast
Stack Overflow Architecture Update - Now At 95 Million Page Views A Month
[转]So You Want To Be A Producer
Hibernate 异常之:associate a collection with two ...
最新问答
更多sp_updatestats是否导致SQL Server 2005中无法访问表?(Does sp_updatestats cause tables to be inaccessible in SQL Server 2005?)
如何创建一个可以与持续运行的服务交互的CLI,类似于MySQL的shell?(How to create a CLI that can interact with a continuously running service, similar to MySQL's shell?)
AESGCM解密失败的MAC(AESGCM decryption failing with MAC)
Zurb Foundation 4 - 嵌套网格对齐问题(Zurb Foundation 4 - Nested grid alignment issues)
湖北京山哪里有修平板计算机的
SimplePie问题(SimplePie Problem)
在不同的任务中,我们可以同时使用多少“上下文”?(How many 'context' we can use at a time simultaneously in different tasks?)
HTML / Javascript:从子目录启用文件夹访问(HTML/Javascript: Enabling folder access from a subdirectory)
为什么我会收到链接错误?(Why do I get a linker error?)
如何正确定义析构函数(How to properly define destructor)
Copyright ©2023 peixunduo.com All Rights Reserved.粤ICP备14003112号
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们(neng862121861#163.com),本站将尽快处理。谢谢合作!