V.Vidhya Logo

V.Vidhya

Array Cumulative


Q1.

Write a JavaScript program to get the first n elements of an array, where n can be any positive number.

// for array [7, 9, 0, -2] and n = 3

// output
[7, 9, 0]

Q2.

Write a JavaScript program to get the last n elements of an array, where n can be any positive number.

// for array [7, 9, 0, -2] and n = 3

// output
[9, 0, -2]

Q3.

Write a JavaScript program to check whether a string is blank or not.


Q4.

Write a JavaScript program to strip leading and trailing spaces from a string.


Q5.

Write a JavaScript program to check if an element exists in an array or not.


Q6. (Adv.)

Write a JavaScript program to test whether the character from a given word at the given index is in lower case or not.

word - JavaScript
index - 3

// so character at index 3 in JavaScript is a
// which is in lowercase

// output
The character at index 3 in JavaScript is 'a', which is in lowercase.

index - 4

// so character at index 4 in JavaScript is S
// which is not in lowercase

// output
The character at index 4 in JavaScript is 'S', which is not in lowercase.

Prev Post
Nested Array
Next Post
for (loop) I