LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-19-2023, 06:23 PM   #1
pizzipie
Member
 
Registered: Jun 2005
Location: Hayden, ID
Distribution: Ubuntu 20.04
Posts: 441

Rep: Reputation: 12
Having Trouble deciphering Console.entries/keys/values


Hi,

The structure I'm working with is shown in attachment which is what is returned from my PHP script.It is a large string "data". This is converted to an object "obj"with up to 80 elements each of which an array ?? obj of 15 elements.

As you see below" alert(records[0].Company);" returns the data properly.

PROBLEM: " alert(records[0].x); " returns undefined I'm trying to iterate each records 15 elements to use in a table. Is there an easier way to do this???

Code:
function viewCompanyRecords(data) {
	
const obj = JSON.parse(data);

const records=Object.values(obj);
const myindex=Object.keys(records[0]);

alert("myindex[3]: "+myindex[3]+"Type is: "+typeof myindex[3]);   =  myindex[3]: Company Type is: string
var x=myindex[3];

alert(records[0].Company);                                        =  Apple Mini Ipad - There are 14 other elements in the array to show for each of 80 records.

alert(records[0].x);                                              =  undefined

}
Attached Thumbnails
Click image for larger version

Name:	Selection_001.png
Views:	10
Size:	19.7 KB
ID:	40493  
 
Old 02-19-2023, 11:09 PM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,869
Blog Entries: 1

Rep: Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870
I guess you mean 'the key is in variable x':
Code:
x='Company';
alert(records[0][x]);

Last edited by NevemTeve; 02-19-2023 at 11:15 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need Help Deciphering MPlayer Error During Make Harpo Linux - Software 3 09-07-2009 09:18 AM
[SOLVED] deciphering dd output schneidz Linux - Software 7 06-03-2009 12:39 PM
Need help on deciphering my IPTABLES jun_tuko Linux - Security 2 11-24-2005 12:02 PM
Help deciphering this log entry Scruff Linux - Security 6 11-24-2003 07:15 PM
Help in deciphering a msg during install? kkathman Linux - Newbie 2 10-05-2003 11:08 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:25 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration