In a part of my code, I am extracting data from a JSON file and place it in an object based array.
I receive the data successfully and can put each on on single object within an array. the only issue is, I want to give a name to each object.
var playlist_data = {
"Music1": {
"soundcloud": "Soundcloud Music 1",
"spotify": "Spotify Music 1"
},
"Music2": {
"soundcloud": "Soundcloud Music 2",
"spotify": "Spotify Music 2"
},
"Music3": {
"soundcloud": "Soundcloud Music 3",
"spotify": "Spotify Music 3"
},
"Music4": {
"soundcloud": "Soundcloud Music 4",
"spotify": "Spotify Music 4"
}
};
var links = [];
$.each(playlist_data, function(index, element) {
links.push({
spotify: element.spotify,
soundcloud: element.soundcloud,
});
});
console.log(links);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
In the above code seems like replicating the same JSON data but it is a simplified version.
So in result I would like to call it like links.Music2
and links.Music2.spotify