Object Manipulation
9 JavaScript object manipulation challenges, each with test cases you can run in the browser.
- swapValues — Easy. Given an object with two properties 'a' and 'b', swap the values of 'a' and 'b'. Return the modified object.
- invertObject — Medium. Given an object, create a new object where the keys become the values and the values become the keys. If multiple original keys have the sam
- countProperties — Easy. Given an object, return the total number of properties it has.
- hasProperty — Easy. Write a function that checks if an object has a given property.
- mergeObjects — Easy. Given two objects, merge them into a single new object. If a key exists in both objects, the value from the second object should be used.
- getObjectValues — Easy. Given an object, return an array of its values.
- cloneObject — Easy. Create a shallow clone of an object. A shallow clone means that the new object is a copy of the top-level properties of the original object.
- isObjectEmpty — Easy. Given an object, return true if it has no properties, and false otherwise.
- getProperty — Medium. Safely retrieve a nested property from an object using a string path (e.g., 'a.b.c'). If any part of the path is undefined, return undefined