I want to take a JSON as input and produce 2 arrays, one contains only keys and the other contains only value. But if a key and value are numerically equal then that pair won’t take place in these arrays. How can I solve that?
>Solution :
You can iterate over key,values of an object by using Object.entries and then check if key and value are diffrent, put them in the related array. like this:
let obj = {a:5, b:6, c:3, '1':4,'2':2};
let keys = [] , values = [];
Object.entries(obj).forEach(([key,value])=> {
if(key != value){
keys.push(key);
values.push(value)
}
});
console.log('keys:',keys);
console.log('values:', values);