给数组添加一个key值:
var arr = [1,2,3]; console.log(arr); //[1,2,3] arr= arr.map((item) => ({ name: item })) console.log(arr); //[{name:1},{name:2},{name:3}]
数组或者对象转换成字符串以及字符串转换成对象或者数组:
var arr = [1,2,3]; console.log(arr); //[1,2,3] arr=JSON.stringify(arr) console.log(arr); //"[1,2,3]" var brr = JSON.parse(arr) console.log(brr) //[1,2,3]