I have an object (myObj) which I want to set it to an Immutable Map that has key value shape and value is a list or an array.
const myObj = {
"a": 1,
"b": 2,
};
now I want to set this object into:
const x = Immutable.Map({
"content": []
})
how can I get the blow result?
{"content": [
{
"a": 1,
"b": 2,
}
]
}
I have already tried : myObj = myObj.set("content", x) but this would not make the content value as an array.
Map
expects [[K, V]]
structure for adding values, also myObj.set("content", x)
is right as myObj
is not Map
it's just simple object
const myObj = { "a": 1, "b": 2, }; const x = Immutable.Map([["content",[myObj]]]) console.log(x)
<script src="https://cdnjs.cloudflare.com/ajax/libs/immutable/3.8.2/immutable.js"></script>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.