How to get all values of an object

Joined
Mar 26, 2022
Messages
1
Reaction score
0
So I turned my MySQL database into a string which is being sent to the subpage "/customers" but... I need to sort the data. Currently, I have a script that shows each object's value using fetch (express.js obviously) like {id: 1, username: user, content: test} or {id: 2, username: user, content: test2 and the actual string that is displaying my "stringified" database looks like this [{"id": 1, "username": "user", "content: "test"},{"id": 2, "username": "user", "content: "test2"}], I think you get the point. But back to my main question, is there a way to sent all of the values for a certain value? eg. console.log(data.id) to print out 16 values. Thanks everyone, Alek
 
Joined
Mar 11, 2022
Messages
227
Reaction score
32
???
Seriously. There is no print_r or var dumb in js. But there is work arounds. What exatly is your goal?

Completely untested. But you may go from there

This function should return an array of values
Code:
function keyArrayBack(objectArray,key){
      var back=new Array();
      for(var i =0; i<objectArray.length; i++){
           back.push(objectArray[i][key]));
      }
      return back;
}

var oa=[{"id": 1, "username": "user", "content: "test"},{"id": 2, "username": "user", "content: "test2"}];
console.log(keyArrayBack(oa,'id'));
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top