1

I am pushing a string to a string. But, after returning the array surprisingly I am getting the "1". I inspected this carefully, array is creating but before returning it is returning just 1. Following is my code:

enter image description here

4
  • 4
    Yes, 1 is the expected value, push returns the new length of the array. Commented Mar 2, 2021 at 10:02
  • Oh, great for clarifying this. But, if I want the array in return what will be the procedure? Commented Mar 2, 2021 at 10:05
  • 2
    ??? return arr;. Commented Mar 2, 2021 at 10:06
  • 1
    you can try returning arr by return arr, becasue you have updated arr in arr only Commented Mar 2, 2021 at 10:06

1 Answer 1

2
arr.push() - return the new array length

So, if you have empty array after push this.alertMessage - you get 1(arr.length)

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

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.