SpadeX
May 25, 2022, 12:25pm
1
Here is my data and I want to make the array single image ID only not repeat I’d but needs it’s cords data with new array. I work ing in node js
[
{
"insta_image_id": "145",
"insta_gallery_id": 8,
"img_src": "http://res.cloudinary.com/apk911/image/upload/v1653385260/cen5xxzc4dkrjp6lkl5i.jpg",
"product_id": "4585133801506",
"top_cord": "162",
"left_cord": "212"
},
{
"insta_image_id": "145",
"insta_gallery_id": 8,
"img_src": "http://res.cloudinary.com/apk911/image/upload/v1653385260/cen5xxzc4dkrjp6lkl5i.jpg",
"product_id": "4585133408290",
"top_cord": "119",
"left_cord": "394"
},
{
"insta_image_id": "145",
"insta_gallery_id": 8,
"img_src": "http://res.cloudinary.com/apk911/image/upload/v1653385260/cen5xxzc4dkrjp6lkl5i.jpg",
"product_id": "4585127051298",
"top_cord": "54",
"left_cord": "25"
},
{
"insta_image_id": "147",
"insta_gallery_id": 8,
"img_src": "http://res.cloudinary.com/apk911/image/upload/v1653385308/tmgq9i0jiufwx1hy9vb9.jpg",
"product_id": "4585137668130",
"top_cord": "194",
"left_cord": "413"
},
{
"insta_image_id": "147",
"insta_gallery_id": 8,
"img_src": "http://res.cloudinary.com/apk911/image/upload/v1653385308/tmgq9i0jiufwx1hy9vb9.jpg",
"product_id": "4585133899810",
"top_cord": "38",
"left_cord": "212"
}
]
hello and welcome back to fcc forum
about your question, not sure i comprehend that well, would you mind elaborate on this, thanks
I wanted this type array
[
{
"insta_image_id": "145",
"insta_gallery_id": 8,
"img_src": "http://res.cloudinary.com/apk911/image/upload/v1653385260/cen5xxzc4dkrjp6lkl5i.jpg",
"product_id": "4585133801506",
"0" => {
"product_id": "4585133801506",
"top_cord": "162",
"left_cord": "212"
},
"1" => {
"product_id": "4585133408290",
"top_cord": "119",
"left_cord": "394"
},
"2" => {
"product_id": "4585127051298",
"top_cord": "54",
"left_cord": "25"
}
},
{
"insta_image_id": "147",
"insta_gallery_id": 8,
"img_src": "http://res.cloudinary.com/apk911/image/upload/v1653385308/tmgq9i0jiufwx1hy9vb9.jpg",
"0" => {
"product_id": "4585137668130",
"top_cord": "194",
"left_cord": "413"
},
"1" => {
"product_id": "4585133899810",
"top_cord": "38",
"left_cord": "212"
}
]
if you need to create new array without duplicates new Set()
function should do the trick
Set - JavaScript | MDN (mozilla.org)
Can I create the associate array
Associate array are PHP concept, I thought you wanted to create unique array😅
You can use map()
function to create array out of array
If this doesn’t help, I found stackoverflow answer
If this doesn’t help I am happy to delve deeper
Thanks @Sboonny for quick response i got the solution .
ILM
May 26, 2022, 1:47pm
8
I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
You can also use the “preformatted text” tool in the editor (</>
) to add backticks around text.
See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).
Thanks for reminding me, by the way I have posted from mobile. Hence it’s show unformatted .
system
Closed
November 26, 2022, 6:09pm
10
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.