lets say I have an array of ID
id = [10,12,13,14,15]
I wish to map the id and get the following output as follow:
"id=10 OR id=12 OR id=13 or id=14 or id=15"
I tried the following but did not get the result as expected
let tempArray= id.map((item, index)=>{
return index ? `id=${item} OR id=${item}`:""
})
You can map each value to the string id=${value}
and then join
the result with " OR "
:
const ids = [10,12,13,14,15]; const str = ids.map((value) => `id=${value}`).join(" OR "); console.log(str);
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.