How to take out the key value in the object whose key value is true, and then join(','). The current data structure is, ,
send_message:{1: true,2:true}, the data structure I want to give to the background is: send_message=1,2&is_live=1
为情所困2017-06-26 10:55:52
Use for...in...:
This way:
const message = { 1: true, 2: true, 3: false };
const arr = [];
for (let item in message) {
if (message[item]) {
arr.push(item);
}
}
console.log(arr.join(','));