I want to convert an object like this:
let obj = {
arabicLang: false,
cancelVisitEmailAlert: false,
canselVisitSmsAlert: false
}
into an array of key-value pairs like this:
[
"arabicLang": false,
"cancelVisitEmailAlert": false,
"canselVisitSmsAlert": false
]
I read all questions in StackOverflow but none of them is my case
i try this but it return key and value in string:
let data = [];
for (const [key, value] of Object.entries(obj)) {
data.push(createData(key, value));
}
function createData(key, value) {
return key + ":" + value;
}
and also try this:
let arr = Array.of(obj)
console.log(arr)
/* output is
[{
arabicLang: false,
cancelVisitEmailAlert: false,
canselVisitSmsAlert: false
}]
*/
it keeps the object container
arabicLang: falseas an element won't work (it's a syntax error), do you want this to be an object:{arabicLang: false}?Arraylike this, if you wanna create anArrayofobjectsuseObject.entries(obj)that will result in[{a: 1}, {b:2}]semicolon comma semicolon comma[arabicLang: false]is invalid syntax we can't really know what you expect it to do. Why do you want an array instead of an object? How do you plan to use that value? Maybe that helps understand what you are trying to achieve.