map()函数根据一个回调函数创建一个新的函数,它会遍历数组中的每一个值
例子
var arr1 = [1,3,5,6,8,19] const map1 = arr1.map(function(singleEl){
return singleEl*2; }) console.log(map1) //返回的map1函数数组为[2,6,10,12,16,38]
回调函数可用的参数
var new_array = arr.map(function callback(currentValue[,index[,array]]){
//返回数组中的单个元素 },thisArg)
参数:
应用
vue中重复渲染组件
<div id='app'> <ele></ele> </div> <script> var child = {
render:function(createElement){
return createElement('p','文字'); } }; Vue.component('ele',{
render:function(createElement){
return createElement('div', Array.apply(null,{
length:5 }).map(function(){
return createElement(Child); }) ); } }); var app = new Vue({
el:'#app' }) </script>
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/222108.html原文链接:https://javaforall.net
