Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

separate array-Elements

Engaged ,
Mar 04, 2020 Mar 04, 2020

Hello!

 

How one can separate the contents with split() or something else? In the following case it doesn´t work. Okay, I think it´s becausse it is a multidimensional array. Isn´t it?

 

var string1 = "first string";
var string2 = "second string";
var string3 = "third string";
var string4 = "fourth string";
var string5 = "fifth string";
var x = new Array();
x = [string1, string2, string3, string4, string5];


alert(x.split());

 

What I want to have is an alert-output like:

 

first string

second string

third string

fourth string

fifth string

 

 

 

TOPICS
Scripting
484
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Mar 04, 2020 Mar 04, 2020

Hi cmoke73,

you already have an array in variable x . Method split() is not available for arrays. That's a method for a string.

Instead use join() with a seperator charakter like that:

alert( x.join("\r") );

 

Regards,
Uwe Laubender

( ACP )

Translate
Community Expert ,
Mar 04, 2020 Mar 04, 2020

Hi cmoke73,

you already have an array in variable x . Method split() is not available for arrays. That's a method for a string.

Instead use join() with a seperator charakter like that:

alert( x.join("\r") );

 

Regards,
Uwe Laubender

( ACP )

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Mar 05, 2020 Mar 05, 2020
LATEST

So simple! (if one knows the answer)

But illogical for me, because join means to attach, to bind, to connect. Not to devide, to separate. 😞

 

Thank you Uwe

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines