Register Now

Login

Lost Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

What will be the output of the following JavaScript code?
var values=[1,2,3,4]
var ans=values.slice(1);
document.writeln(ans);

What will be the output of the following JavaScript code?
var values=[1,2,3,4]
var ans=values.slice(1);
document.writeln(ans);
a) 1, 2, 3, 4
b) 2, 3, 4
c) 1, 3, 4
d) error

Answer: b
Explanation: The slice() function is used to extract values from an array. In this code, slice() creates a new array starting from index 1, removing the first element “1”, and returning the remaining elements “2, 3, 4”.

Join The Discussion