我知道有很多这样的话题.我知道基础知识:.forEach()在原始数组和.map()新数组上运行.
就我而言:
function practice (i){
return i+1;
};
var a = [ -1, 0, 1, 2, 3, 4, 5 ];
var b = [ 0 ];
var c = [ 0 ];
console.log(a);
b = a.forEach(practice);
console.log("=====");
console.log(a);
console.log(b);
c = a.map(practice);
console.log("=====");
console.log(a);
console.log(c);
Run Code Online (Sandbox Code Playgroud)
这是输出:
[ -1, 0, 1, 2, 3, 4, 5 ]
=====
[ -1, 0, 1, 2, 3, 4, 5 ]
undefined
=====
[ -1, 0, 1, 2, 3, 4, 5 ] …Run Code Online (Sandbox Code Playgroud) 我有一个对象数组:
[
{ key : '11', value : '1100', $$hashKey : '00X' },
{ key : '22', value : '2200', $$hashKey : '018' }
];
Run Code Online (Sandbox Code Playgroud)
如何通过JavaScript将其转换为以下内容?
{
"11": "1000",
"22": "2200"
}
Run Code Online (Sandbox Code Playgroud)