Sunday, 26 July 2020

remove number 12 from the array below

Q: Which of the following represents the method used to remove number 12 from the array below?
var values=[2, 4, 6, 10, 12]
a. values.remove(at: 4)
b. values.remove(at: 12)
c. values.append(12, at: 5)
d. remove("12")

Solution: values.remove(at: 4)

The above statement is used to remove the element 12 from array by using remove(at:index) method. 12 is at the index 4 , therefore at: 4 is used

The output will be 2 4 6 10 after removing 12.

No comments:

Post a Comment