2

i have an array that has one element and i want to use proarray.shift();

var proarray=[];
proarray[0]=1;
//...
proarray.shift();
//...
proarray[i]=5;

but when i do, it stops the program. does it delete the array? if it does, what should i do to prevent that? cuz i need that array for later.

and also i tried to use

var proarray=[];
    proarray[0]=1;
    //...
    array.splice(0,1);
    //...
    proarray[i]=5;

but it didn't work.

what should i do?

0

1 Answer 1

1

From the docs.

The shift method removes the element at the zeroeth index and shifts the values at consecutive indexes down, then returns the removed value. If the length property is 0, undefined is returned.

The program is likely stopping because you are accessing an index in the array that no longer exists.

Sign up to request clarification or add additional context in comments.

1 Comment

@ali sorkhi Acceptable as the answer?

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.