JavaScript Arrays and Objects

Description: JavaScript Arrays and Objects Quiz
Number of Questions: 15
Created by:
Tags: javascript arrays objects data structures
Attempted 0/15 Correct 0 Score 0

Which of the following is not a built-in method of JavaScript arrays?

  1. push()

  2. pop()

  3. shift()

  4. filter()


Correct Option: D
Explanation:

The filter() method is not a built-in method of JavaScript arrays. It is a method of the Array.prototype object, which is added to all arrays by default.

What is the purpose of the join() method in JavaScript arrays?

  1. To join all the elements of an array into a single string

  2. To add an element to the end of an array

  3. To remove the last element from an array

  4. To sort the elements of an array


Correct Option: A
Explanation:

The join() method joins all the elements of an array into a single string, separated by a specified separator.

Which of the following is not a built-in method of JavaScript objects?

  1. hasOwnProperty()

  2. toLocaleString()

  3. valueOf()

  4. forEach()


Correct Option: D
Explanation:

The forEach() method is not a built-in method of JavaScript objects. It is a method of the Object.prototype object, which is added to all objects by default.

What is the purpose of the Object.keys() method in JavaScript?

  1. To return an array of all the keys in an object

  2. To return an array of all the values in an object

  3. To return the number of keys in an object

  4. To return the number of values in an object


Correct Option: A
Explanation:

The Object.keys() method returns an array of all the keys in an object, in the same order as they were defined.

Which of the following is not a valid way to access the properties of an object in JavaScript?

  1. object.property

  2. object['property']

  3. object[property]

  4. object.getProperty()


Correct Option: D
Explanation:

The object.getProperty() syntax is not a valid way to access the properties of an object in JavaScript. The correct syntax is object.property, object['property'], or object[property].

What is the purpose of the Array.from() method in JavaScript?

  1. To convert an array-like object to an array

  2. To convert an array to an array-like object

  3. To create a new array with the same elements as an existing array

  4. To sort the elements of an array


Correct Option: A
Explanation:

The Array.from() method converts an array-like object (such as a string, a NodeList, or an HTMLCollection) to an array.

Which of the following is not a valid way to iterate over the elements of an array in JavaScript?

  1. for (let i = 0; i < array.length; i++) { ... }

  2. for (const element of array) { ... }

  3. array.forEach((element, index) => { ... })

  4. array.map((element, index) => { ... })


Correct Option: D
Explanation:

The array.map() method is not a valid way to iterate over the elements of an array in JavaScript. It is a method that creates a new array with the results of calling a specified function on each element of the original array.

What is the purpose of the Object.assign() method in JavaScript?

  1. To copy the properties of one object to another

  2. To merge two objects into a new object

  3. To create a new object with the same properties as an existing object

  4. To delete the properties of an object


Correct Option: A
Explanation:

The Object.assign() method copies the properties of one object to another. It can be used to merge two objects into a new object, or to create a new object with the same properties as an existing object.

Which of the following is not a valid way to define a JavaScript object?

  1. const object = {};

  2. const object = new Object();

  3. const object = { property: value };

  4. const object = [property: value]


Correct Option: D
Explanation:

The const object = [property: value] syntax is not a valid way to define a JavaScript object. The correct syntax is const object = {};, const object = new Object();, or const object = { property: value };.

What is the purpose of the Array.prototype.sort() method in JavaScript?

  1. To sort the elements of an array in ascending order

  2. To sort the elements of an array in descending order

  3. To sort the elements of an array in a custom order

  4. To reverse the order of the elements in an array


Correct Option: C
Explanation:

The Array.prototype.sort() method sorts the elements of an array in a custom order. The order is determined by a compare function that is passed to the method.

Which of the following is not a valid way to access the elements of an object in JavaScript?

  1. object.property

  2. object['property']

  3. object[property]

  4. object.getProperty()


Correct Option: D
Explanation:

The object.getProperty() syntax is not a valid way to access the properties of an object in JavaScript. The correct syntax is object.property, object['property'], or object[property].

What is the purpose of the Array.prototype.reduce() method in JavaScript?

  1. To reduce an array to a single value

  2. To reduce an array to a new array

  3. To reduce an array to an object

  4. To reduce an array to a string


Correct Option: A
Explanation:

The Array.prototype.reduce() method reduces an array to a single value. The value is determined by a reduce function that is passed to the method.

Which of the following is not a valid way to create a new JavaScript object?

  1. const object = {};

  2. const object = new Object();

  3. const object = { property: value };

  4. const object = [];


Correct Option: D
Explanation:

The const object = []; syntax is not a valid way to create a new JavaScript object. The correct syntax is const object = {};, const object = new Object();, or const object = { property: value };.

What is the purpose of the Object.freeze() method in JavaScript?

  1. To prevent an object from being modified

  2. To prevent an object from being deleted

  3. To prevent an object from being accessed

  4. To prevent an object from being serialized


Correct Option: A
Explanation:

The Object.freeze() method prevents an object from being modified. Once an object is frozen, its properties cannot be added, removed, or changed.

Which of the following is not a valid way to iterate over the properties of an object in JavaScript?

  1. for (const property in object) { ... }

  2. for (const [property, value] of Object.entries(object)) { ... }

  3. object.forEach((property, value) => { ... })

  4. object.map((property, value) => { ... })


Correct Option: C
Explanation:

The object.forEach((property, value) =&gt; { ... }) syntax is not a valid way to iterate over the properties of an object in JavaScript. The correct syntax is for (const property in object) { ... }, for (const [property, value] of Object.entries(object)) { ... }, or object.map((property, value) =&gt; { ... }).

- Hide questions