I have this json and I want to show the value of its keys either by console or by a window.
{
"commerce_brand":"MASTERCARD",
"commerce_brand":"visa",
"commerce_brand":"otros"
}
I have this json and I want to show the value of its keys either by console or by a window.
{
"commerce_brand":"MASTERCARD",
"commerce_brand":"visa",
"commerce_brand":"otros"
}
The json as you present it will always throw you "commerce_brand": "others" since you are using the same index or key with different values, so you are always overwriting and the result will be always the last one:
let json = {
"commerce_brand":"MASTERCARD",
"commerce_brand":"visa",
"commerce_brand":"otros"
}
console.log(json);
I imagine that you want to get several values within commerce_brand , for this commerce_brand it must be an array like this:
let json = {
"commerce_brand":["MASTERCARD",
"visa",
"otros"]
}
console.log(json);
and you can scroll it like this:
let json = {
"commerce_brand":["MASTERCARD",
"visa",
"otros"]
}
json["commerce_brand"].forEach((elemento, indice) => {
console.log(elemento);
});
I hope it helps you
The specification RFC7159 concerning JSON says that object names should be unique. Although this is only a recommendation it is much more practical if you have to convert it to objects in javascript. Your structure could be converted to manipulate it easily in this way:
{ "commerce_brand": [ "MASTERCARD", "visa", "otros" ] }