Converting JavaScript Array To JSON Format

后端 未结 2 1310
滥情空心
滥情空心 2021-01-29 14:16

i have an array like this coming back response from the server:

[
    \"111\",
    \"1010\",
    \"111\",
    \"1010\",
    \"1010\"
]

i want t

2条回答
  •  南笙
    南笙 (楼主)
    2021-01-29 14:53

    You can use map() to create a new array with the results of calling a provided function on every element in the calling array

    var arr = [
        "111",
        "1010",
        "111",
        "1010",
        "1010"
    ]
    
    var res = arr.map(i => ({'branch': i}));
    console.log(res);

提交回复
热议问题