Array Get Value

Joined
Jul 9, 2023
Messages
25
Reaction score
0
Hello

it is Array. var array1 = [];

$.("array1").each(function(idx, item){
var MateoName= item.Name;

var NoahSubject = getvalue(item, idx);
...........
});

Isn’t this how you do it?

var array is
1111.png


1) How do I get Mateo of HeaderName?
var Name = array1.Get
2) How do I get Noah of Subject Name?
var Math = array1.Get

please answer me. I'm waiting for your reply.
 

Attachments

  • 1111.png
    1111.png
    26.3 KB · Views: 13
Last edited:
Joined
Aug 22, 2023
Messages
42
Reaction score
7
You are conducting this with an incorrect approach! You merely need to use document.GetElementById. Perhaps .value regarding what you would like to accomplish!
JavaScript:
var Name = document.getElementById("array1").value;
var other = document.getElementById("array2").value;
//Unfamiliar with solution desired, or...
var Name = document.getElementById("array1");
var other = document.getElementById("array2");
 
Last edited:
Joined
Jul 9, 2023
Messages
25
Reaction score
0
You are conducting this with an incorrect approach! You merely need to use document.GetElementById. Perhaps .value regarding what you would like to accomplish!
JavaScript:
var Name = document.getElementById("array1").value;
var other = document.getElementById("array2").value;
//Unfamiliar with solution desired, or...
var Name = document.getElementById("array1");
var other = document.getElementById("array2");
How do I get Noah of Subject Name?
please answer me. I'm waiting for your reply.

it is Array. var array1 = [];

$.("array1").each(function(idx, item){
var MateoName= item.Name;

var NoahSubject = getvalue(item, idx);
...........
});

Isn’t this how you do it?
 
Last edited:
Joined
Jul 4, 2023
Messages
366
Reaction score
41
Did you tried in that way

[ on-line ]
JavaScript:
const array1 = [
  { 'name':'James', 'subject':'English', 'score':80 },
  { 'name':'Mateo', 'subject':'Chinese', 'score':50 },
  { 'name':'Noah',  'subject':'Math',    'score':40 },
]

/* for demonstration */
const pre = document.createElement('pre');

pre.innerHTML = array1[0].name + ' ' + array1[0].subject;
pre.innerHTML += '\n';
pre.innerHTML += `${array1[0].name} ${array1[0].subject}`;

pre.innerHTML += '\n\n';

for (const row of array1) {
  pre.innerHTML += `${row.name}, ${row.subject}:${row.score}.\n`;
}

pre.innerHTML += '\n\n';

for (const index in array1) {
  pre.innerHTML += `${(index*1+1)}. ${array1[index].name} ${array1[index].subject}:${array1[index].score}.\n`;
}

document.body.appendChild(pre);
or
[ on-line ]
JavaScript:
const array1 = [
  [ 'James', 'English', 80 ],
  [ 'Mateo', 'Chinese', 50 ],
  [ 'Noah',  'Math', 40 ]
]

/* for demonstration */
const pre = document.createElement('pre');

pre.innerHTML = array1[0][0] + ' ' + array1[0][1];
pre.innerHTML += '\n';
pre.innerHTML += `${array1[0][0]} ${array1[0][1]}`;

pre.innerHTML += '\n\n';

for (const row of array1) {
  pre.innerHTML += `${row[0]}, ${row[1]}:${row[2]}.\n`;
}

pre.innerHTML += '\n\n';

for (const index in array1) {
  pre.innerHTML += `${(index*1+1)}. ${array1[index][0]} ${array1[index][1]}:${array1[index][2]}.\n`;
}

document.body.appendChild(pre);
 
Last edited:
Joined
Jul 9, 2023
Messages
25
Reaction score
0
Did you tried in that way

[ on-line ]
JavaScript:
const array1 = [
  { 'name':'James', 'subject':'English', 'score':80 },
  { 'name':'Mateo', 'subject':'Chinese', 'score':50 },
  { 'name':'Noah',  'subject':'Math',    'score':40 },
]

/* for demonstration */
const pre = document.createElement('pre');

pre.innerHTML = array1[0].name + ' ' + array1[0].subject;
pre.innerHTML += '\n';
pre.innerHTML += `${array1[0].name} ${array1[0].subject}`;

pre.innerHTML += '\n\n';

for (const row of array1) {
  pre.innerHTML += `${row.name}, ${row.subject}:${row.score}.\n`;
}

pre.innerHTML += '\n\n';

for (const index in array1) {
  pre.innerHTML += `${(index*1+1)}. ${array1[index].name} ${array1[index].subject}:${array1[index].score}.\n`;
}

document.body.appendChild(pre);
or
[ on-line ]
JavaScript:
const array1 = [
  [ 'James', 'English', 80 ],
  [ 'Mateo', 'Chinese', 50 ],
  [ 'Noah',  'Math', 40 ]
]

/* for demonstration */
const pre = document.createElement('pre');

pre.innerHTML = array1[0][0] + ' ' + array1[0][1];
pre.innerHTML += '\n';
pre.innerHTML += `${array1[0][0]} ${array1[0][1]}`;

pre.innerHTML += '\n\n';

for (const row of array1) {
  pre.innerHTML += `${row[0]}, ${row[1]}:${row[2]}.\n`;
}

pre.innerHTML += '\n\n';

for (const index in array1) {
  pre.innerHTML += `${(index*1+1)}. ${array1[index][0]} ${array1[index][1]}:${array1[index][2]}.\n`;
}

document.body.appendChild(pre);


Var length = array1.length is 10000
array1.length is 10000.
So, i hope to
for(int i=0; i< array1.length; i++) statement or $.each statement


I hope to
$.("array1").each(function(idx, item){
var MateoName= item.Name;

var NoahSubject = getvalue(item, idx);
...........
});
 
Last edited:
Joined
Jul 4, 2023
Messages
366
Reaction score
41
Can you show, how exactly looks you array, just few values, no need expose 10000 items.
array1.length is 10000.
because the image suggests that you have a table in Excel, or am I wrong?


BTW, 10000 is not a big length of array, that you should worry.
JavaScript:
console.time("preparing an array of length 10000"); // Start measuring the time

const array = new Array(10000).fill().map(() => {
  const min = 1, max = 10000;
  return Math.floor(Math.random() * (max - min + 1)) + min;
});

console.timeEnd("preparing an array of length 10000"); // End measuring the time and display the result in the console

console.log(array.length);
 
Joined
Jul 4, 2023
Messages
366
Reaction score
41

But this code example is Java not Javascript - this is not the same.
Any way, on the picture is how this array looks like
java-array-1.png

i can't see any connection to your previously example
array-1.png


sorry, I can't help you, to mach confused about what you exactly want to do.




and this one below is JQuery - is a popular JavaScript library that simplifies web development by providing a wide range of pre-built functions and features.
$.("array1").each(function(idx, item){
var MateoName= item.Name;

var NoahSubject = getvalue(item, idx);
...........
});
 
Last edited:

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,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top