简体   繁体   中英

How to convert comma separated Query param into KeyValue Pair json object using javascript

I have this Query param that I already converted into JSON.

{"Id":"ZX0123455555,ZX0123455555,ZX0123455545"}

And I want it to become looks like this:

{ "Id": "ZX0123455555", "Id": "ZX0123455555", "Id": "ZX0123455545" }

Just to simplify my JSon schema validation. Thanks

you can't have an object with the same keys and multiply values but you can have this array:

 const myObject = {"Id":"ZX0123455555,ZX0123455555,ZX0123455545"}; const myArray = myObject.Id.split(',') const newArray = myArray.map((e)=>{return {Id:e}}) console.log(newArray)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM