Explore Courses Blog Tutorials Interview Questions
0 votes
in Java by (13.1k points)

I was trying to convert a list into a string by iterating into it using the below code:

var temp = $.each(value, function(idx2,val2) {                    

     var str = idx2 + ":" + val2;


     return str;

}).get().join(", "); 

Can anyone help me what is wrong in this code?

1 Answer

0 votes
by (26.7k points)

Basically, if you have added the value as an associative array, then this code would works:

var value = { "aaa": "111", "bbb": "222", "ccc": "333" };

var temp = [];

$.each(value, function(idx2,val2) {                    

  var str = idx2 + ":" + val2;



console.log(temp.join(", "));

Also, each() function can only help you to iterate over an array.

I hope this will help.

Want to know more about Java? Prefer this tutorial on Learn Java.

Want to become a Java expert? join Java Certification now!!

Related questions

0 votes
1 answer
0 votes
0 answers
0 votes
1 answer
asked Feb 6, 2021 in Java by dante07 (13.1k points)
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers!

29.3k questions

30.6k answers


104k users

Browse Categories