美文网首页
JavaScript map方法的运用

JavaScript map方法的运用

作者: 东到西歪 | 来源:发表于2017-11-11 12:39 被阅读17次

array 对象的map()方法

语法
array.map(function(currentValue,index,arr), thisValue)

currentValue 当前函数值

过程:对array进行遍历,从0到array.length-1,并运行function,最好并返回一个值于。

实质:map方法封装了对array对象的遍历过程。

实例

data为数组
d为data的值
ontainer.innerHTML = data.map(function(d){
            if(input != null && input.length > 0){
                d = d.replace(new RegExp(input, 'g'),'<spanclass="found">' + input + '</span>');
            }
            return "<div>" + d + "</div>"
})

相关文章

网友评论

      本文标题:JavaScript map方法的运用

      本文链接:https://www.haomeiwen.com/subject/tsuwmxtx.html