Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- json='[ { "Data": 2019, "IdJudet": "09,18" }, { "Data": 2019, "IdJudet": "09,18, 20, 03" }, { "Data": 2019, "IdJudet": "09" }, { "Data": 2019, "IdJudet": null } ]';
- obj = JSON.parse(json)
- const ids = obj
- // get only the required field
- .map((item) => item.IdJudet)
- // filter away null values and empty strings
- .filter(Boolean)
- // split by comma and trim spaces
- .map((IdJudet) => IdJudet.split(",").map(id => id.trim()))
- // reduce arrays to your result
- .reduce((result, ids) => result.concat(ids), [])
- // remove duplicates
- const result = ids.filter((id, i) => ids.indexOf(id) === i)
- console.log(result);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement