Array.prototype.clear = function(){
this = new Array();
return true;
}
That code raise an invalid assignment left-hand side error.
How do I change the object itself within one of his methods?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can’t change the reference of what the
thisvalue points to, it is immutable.If you want to clear the current array, you can simply set its
lengthproperty to zero:Edit: Looking at the comment made to the sasuke’s answer, you could empty the array as in my first example, and then
pushthe elements of another array, for example: