let a, b, c;
a = [0, 1, 2, 3, 4];
b = a.join("|"); // array => sting
console.log(typeof b);
console.log(b);
c = b.split("|"); // string => array
console.log(typeof c);
console.log(c);
let x, y, z;
x = '{"name": "lisa", "age": 20}';
y = JSON.parse(x); // string => jsonObject
console.log(typeof y);
console.log(y);
z = JSON.stringify(y); // jsonObject => string
console.log(typeof z);
console.log(z);
js中字符串和数组, 字符串和json对象的相互转化
最新推荐文章于 2023-07-03 20:33:23 发布