I am using xml2js to convert xml to js object and add new nodes to the content
Ex1:
<abc>
<my-node>123</my-node>
<my-node>456</my-node>
</abc>
Ex2:
<abc>
<my-node>123</my-node>
</abc>
In the Ex1, the my-node property will be an array whereas in the Ex2, it will be non-array item.
How to add extra my-node to the same. I can do in below format but looking for better solution?
if(typeof abc.my-node == Array){
abc.my-node.push(xxx);
} else {
//create empty array
//add existing element
//add xxx
//set the array to json object
}