javascript - How to take out the key value whose key value is true in object, and then join(',')
漂亮男人
漂亮男人 2017-06-26 10:53:52
0
2
876

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

漂亮男人
漂亮男人

reply all(2)
为情所困

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(','));
某草草
Object.keys(message).filter(k => message[k] === true).join(',')
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template