0
var ar= [];
ar[0] = 'abc|def';
ar[1] = ['www|aaa', 'bb|cct', 'oo|kopp'];

for(var i=0; i<ar[1].length; i++) {
    var f = ar[1][i].split['|'];
    alert(f[0]); //error f is undefined 
}

Why there is error on split function? I am new to javascript.

Thanks.

2 Answers 2

5

split is a function, not an array:

var f = ar[1][i].split('|');
Sign up to request clarification or add additional context in comments.

Comments

2

You have to invoke split like this:

var f = ar[1][i].split('|');
//                    ^ instead of ['|']

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.