Conversion between json and array

{other:1} = > [{name: "other", value:1}]
now if you want to achieve the above transformation, ask for the great guidance

.
Mar.13,2022

var a = {other: 1};

var b = Object.keys(a).map(function(item) {
    return {
        name: item,
        value: a[item]
    }
})

console.log(b)

const obj = {other:1};

const array = [];
Object.keys(obj).forEach((item, idx) => {
    array.push([{
        name: item,
        value: Object.values(obj)[idx]
    }]);
});

console.log(array);

first of all, this thing is not called JSON , JSON is an acronym for JavaScript Object Notation, and {key: value} is a normal object ( object ). You will ask this question to show that you are not familiar with js, so I guess your requirement is probably not necessary, you might as well explain why you want to do this transformation, want to traverse all the key-value pairs of an object can use for-in traversal. Going back to the question itself, you can write this in the latest syntax:

let obj = { other: 1 }

let entries = Object.keys(obj).map(key => { name: key, value: obj[key] })

in fact, there is a Object.entries method in the new proposal, which can be used in the

const obj = {other:1};

let newObj = Object.keys(obj).reduce((arr,item)=>{
     return (arr.push({
         name: item,
         value: obj[item]
     }),arr)
},[])

console.log(newObj)
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1bf35c4-31e91.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1bf35c4-31e91.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?