筛选
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <script> let allArr = [ { "a": "aaaaaaaa", "b": "bbbbbbbb", "c": "cccccccc", "d": "dddddddd", "e": "eeeeeeee" }, { "a": "aaaaaaaa", "b": "bbbbbbbb", "c": "cccccccc", "d": "dddddddd", "e": "eeeeeeee" }, { "a": "aaaaaaaa", "b": "bbbbbbbb", "c": "cccccccc", "d": "dddddddd", "e": "eeeeeeee" } ]; let arr = ["a", "b", "c", "f"]; // map/forEach let newArr = []; allArr.map((v1, k1) => { let newJson = {};// 关键中间环节 arr.map((v2, k2) => { if( v1.hasOwnProperty(v2) ) { newJson[v2] = v1[v2]; } }); newArr.push(newJson); }) console.log(newArr); </script> </body> </html>
活着就挺好,挺好~