How do I access JSON arrays within array?
1 JSON array:
{
"id": 1,
"company": "Photosnap",
"logo": "./images/photosnap.svg",
"new": true,
"featured": true,
"position": "Senior Frontend Developer",
"role": "Frontend",
"level": "Senior",
"postedAt": "1d ago",
"contract": "Full Time",
"location": "USA Only",
"languages": ["HTML", "CSS", "JavaScript"],
"tools": []
},
How do I access "languages" and made them elements get dynamically created, as well as not created if empty?
35 Replies
Tech it would be an object or array of objects* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse
you also have JSON.stringify() for the reverse.
I did this and it kinda worked I think, am super tired so my brain is out of juice
?
na use the API
or something
hmmmm
okay, will check it out tomorrow. Thanks for the info
then you have a object or array of objects to work with
No chance of you implementing it into the code ? I know I may ask tooo much xD
i just did xD
wait
How would I implement that inot the paragraphs?
As code?
or something
IT broke my code
then remove it didn't need parsed
are you just trying to loop through jobs.languages?
maybe I misunderstood your issue
Yeah yeah
and add them
dynamically into the paragraphs in one go
where they are needed
as well if its empty to not add them
This part
that code you wrote above didn't work? then just use that var?
o wait hah
${job.languages}
These need to be separate paragraphs
and if empty to not show up
But it's confusing me a lot right now
need to be loopy
something like that?
lemmie try it
then you would use ${languageItems} in the full template
did it but something it is not going into the loop fore some reason
š¤
put it in a codepen for me?
sec
But we have no
JSON
xD
sorry I had a bad check too, I'm also tired hah no sleep last night (forgot .length š )
but you need more data or you would not make it past the first for of
You you will want to put a check before your
for (let job of jobs)
too
there I edited to use a for of
for both just cause it might help you understand better and now looks the same >.>;;Was grabbing a snack myself
let me look
xD
make sure to copy the code over cause I will nuke that pen sooner than later
This should make sense since basically we are just duplicating what you already did with jobs
just within the jobs loop
Is my internet back?
I think xD
So same problem as my code
where some are still in 1 paragraph
reverse order
and so on
It has to do with the number of iterations going
inside of loops
but I'm toooo out of energy to wrap my head around it.
yea get some sleep cause at this point not sure what you are after
if you wanted them in the same p just toString() it
hehe
this is how it looks
This is how it needs to look
So each array item needs to be a separate paragraph
and dynamically generated
But it is harder than it looks, or there is some easy way that we don't know of
Show me the full
but go get some sleep, cause at this point I think your issue is CSS hah
and I'm kinda lost still lol cause that is just flex items that you could make from your array not paragraphs
I call them paragraphs since I'm putting items into <p> tag xD
Pretty sure CSS is working
it is just that our logic is not
Either way lets see if someone else jumps in
if not will figure it out somehow
xD
I hope
I had it hardcoded when I was designing and it was working
it i just the JSON insertation that is not
@b1mind I figured it out. Both your and mine solutions work, but yours is much more neater and better
I was overlooking second array in Json file that I thought was "languages" one xD
that was confusing me
order is still a bit off, but hey it mostly works
thanks for all the help!
nice glad you got it working! np
Sorry for bothering you when I should have took a break and came back to it fresh instead. xD
Thanks again!
Now I can sleep without a bother xD