Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
77
rated 0 times [  82] [ 5]  / answers: 1 / hits: 67730  / 13 Years ago, tue, november 15, 2011, 12:00:00

I have the following function:



  function getId(a){
var aL = a.length;
for(i = 0; i < aL; i++ ){
return a[i][2].split(:, 1)[0];
}
}


and when using console.log() within the function instead of return I get all of the values in the loop, and the same goes for document.write. How can I access these values as a string for use in another section of my code?



Thank you in advance.


More From » arrays

 Answers
1

You can do that with yield in newer versions of js, but that's out of question. Here's what you can do:



function getId(a){
var aL = a.length;
var values = [];
for(i = 0; i < aL; i++ ){
values.push(a[i][2].split(:, 1)[0]);
}
return values.join('');
}

[#89121] Sunday, November 13, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
sandra

Total Points: 708
Total Questions: 100
Total Answers: 84

Location: Bosnia and Herzegovina
Member since Thu, Jun 24, 2021
3 Years ago
sandra questions
Tue, Jun 30, 20, 00:00, 4 Years ago
Sun, May 31, 20, 00:00, 4 Years ago
Wed, May 20, 20, 00:00, 4 Years ago
Fri, May 31, 19, 00:00, 5 Years ago
;