Skip to main content
Stack Overflow
  1. About
  2. For Teams

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

Convert javascript array to string

I'm trying to iterate over a "value" list and convert it into a string. Here is the code:

var blkstr = $.each(value, function(idx2,val2) { 
 var str = idx2 + ":" + val2;
 alert(str);
 return str;
}).get().join(", "); 

alert() function works just fine and displays the proper value. But somehow, jquery's .get() function doesn't get the right sort of object and fails. What am I doing wrong?

Answer*

Draft saved
Draft discarded
Cancel
3
  • "Associative array" being a non-JavaScript term for object Commented Jul 26, 2021 at 20:26
  • A JavaScript object is not a JavaScript Array. You should probably inform people that this is not the correct answer to the question because the question was asked incorrectly and the user meant associative array, but for me, it's not what I searched for. Commented Sep 9, 2022 at 17:11
  • @CaleMcCollough the question author had no idea how this is called back when asking, and neither did I. As the other comment here correctly says, "Associative array" is also incorrect as it refers to abstract data structure. In JavaScript, every object is an associative array, including plain array. So to make it more simple I just used "not a plain array" and I stand by this definition. And the answer is correct, it iterates the keys, and collecting the data into plain array that is later converted to string. Commented Sep 9, 2022 at 18:03

lang-js

AltStyle によって変換されたページ (->オリジナル) /