Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

141
Views
How to get array name from json encode to javascript on console.log?

I have an array. I converted php array inside JavaScript. I want to get array's name for my select option. How to get array name on console log?

My code is below;

<script> 
var users= <?php echo json_encode($users) ?>;
        console.log(users);
</script>

[{0: {id:1, name: Alex, email: alex@gmail.com}},

{1: {id:2, name: Jane, email: jane@gmail.com}}]

This is what I get.

But this is what I want.

Alex

Jane

Can you help me please ?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You got use flatMap()

const users = [{0: {id:1, name: "Alex", email: "alex@gmail.com"}},{1: {id:2, name: "Jane", email: "jane@gmail.com"}}]

const parsedUsers = users.flatMap(user=>Object.values(user));

parsedUsers.forEach(user=>console.log(user.name));

about 4 years ago · Juan Pablo Isaza Report

0

you can use @json blade directive :

<script> 
var users= @json($users);
        console.log(users);
</script>
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!