我如何通过一个序列中的所有输入,使用JavaScript?


当前回答

// 使用前端 ECMAScript 6 路径通过 路径 路径 路径 路径 路径 路径 路径 路径 路径 路径 路径 路径 路径 路径 路径 路径 路径 路径 路径 路径

其他回答

// 使用前端 ECMAScript 6 路径通过 路径 路径 路径 路径 路径 路径 路径 路径 路径 路径 路径 路径 路径 路径 路径 路径 路径 路径 路径 路径

var a = ["car", "bus", "truck"]
a.forEach(function(item, index) {
    console.log("Index" + index);
    console.log("Element" + item);
})

如果你想使用 forEach(),它会看起来像 -

theArray.forEach ( element => {
    console.log(element);
});

如果你想使用(),它会看起来像 -

for(let idx = 0; idx < theArray.length; idx++){
    let element = theArray[idx];
    console.log(element);
}

如果你想通过一系列用箭函数的对象旋转:

let arr = [{name:'john', age:50}, {name:'clark', age:19}, {name:'mohan', age:26}]; arr.forEach((person)=>{ console.log('I am ' + person.name + ' and I am ' + person.age + ' old'); })

jQuery 使用 $.map 的方式:

var data = [1, 2, 3, 4, 5, 6, 7];

var newData = $.map(data, function(element) {
    if (element % 2 == 0) {
        return element;
    }
});

// newData = [2, 4, 6];