JavaScript Arrays and Objects
JavaScript Arrays and Objects Quiz
Questions
Which of the following is not a built-in method of JavaScript arrays?
- push()
- pop()
- shift()
- filter()
What is the purpose of the join() method in JavaScript arrays?
- To join all the elements of an array into a single string
- To add an element to the end of an array
- To remove the last element from an array
- To sort the elements of an array
Which of the following is not a built-in method of JavaScript objects?
- hasOwnProperty()
- toLocaleString()
- valueOf()
- forEach()
What is the purpose of the Object.keys() method in JavaScript?
- To return an array of all the keys in an object
- To return an array of all the values in an object
- To return the number of keys in an object
- To return the number of values in an object
Which of the following is not a valid way to access the properties of an object in JavaScript?
- object.property
- object['property']
- object[property]
- object.getProperty()
What is the purpose of the Array.from() method in JavaScript?
- To convert an array-like object to an array
- To convert an array to an array-like object
- To create a new array with the same elements as an existing array
- To sort the elements of an array
Which of the following is not a valid way to iterate over the elements of an array in JavaScript?
- for (let i = 0; i < array.length; i++) { ... }
- for (const element of array) { ... }
- array.forEach((element, index) => { ... })
- array.map((element, index) => { ... })
What is the purpose of the Object.assign() method in JavaScript?
- To copy the properties of one object to another
- To merge two objects into a new object
- To create a new object with the same properties as an existing object
- To delete the properties of an object
Which of the following is not a valid way to define a JavaScript object?
- const object = {};
- const object = new Object();
- const object = { property: value };
- const object = [property: value]
What is the purpose of the Array.prototype.sort() method in JavaScript?
- To sort the elements of an array in ascending order
- To sort the elements of an array in descending order
- To sort the elements of an array in a custom order
- To reverse the order of the elements in an array
Which of the following is not a valid way to access the elements of an object in JavaScript?
- object.property
- object['property']
- object[property]
- object.getProperty()
What is the purpose of the Array.prototype.reduce() method in JavaScript?
- To reduce an array to a single value
- To reduce an array to a new array
- To reduce an array to an object
- To reduce an array to a string
Which of the following is not a valid way to create a new JavaScript object?
- const object = {};
- const object = new Object();
- const object = { property: value };
- const object = [];
What is the purpose of the Object.freeze() method in JavaScript?
- To prevent an object from being modified
- To prevent an object from being deleted
- To prevent an object from being accessed
- To prevent an object from being serialized
Which of the following is not a valid way to iterate over the properties of an object in JavaScript?
- for (const property in object) { ... }
- for (const [property, value] of Object.entries(object)) { ... }
- object.forEach((property, value) => { ... })
- object.map((property, value) => { ... })