0% found this document useful (0 votes)
2 views1 page

JavaScript Object Manipulation Tasks

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views1 page

JavaScript Object Manipulation Tasks

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

Easy:

=> Create an object car with properties brand, model, year. Print them using both
dot and bracket notation.
=> Add a new property color to the car object and delete the year property.
=> Write a function that counts how many properties an object has.

Medium:
=> Write a program that takes an object and returns an array of all its keys and
another array of all its values.
=> Merge two objects {a:1, b:2} and {c:3, d:4} into one using [Link].
=> Write a program to loop through an object and print each key-value pair.
=> Create a function invert(obj) that swaps keys and values (e.g., {a:1, b:2} →
{1:"a", 2:"b"}).

Hard:
=> Create an object that is frozen using [Link]. Try modifying, adding, and
deleting properties. Observe what happens.
=> Implement a function deepClone(obj) that makes a deep copy of a nested object.
=> Given an array of objects (students with name and marks), write a function that
returns the student with the highest marks.
=> Create a function groupBy(arr, key) that groups an array of objects by a
property.
Example:
let people = [
{name: "Alice", age: 20},
{name: "Bob", age: 20},
{name: "Charlie", age: 25}
];
groupBy(people, "age");
// Output: { 20: [Alice, Bob], 25: [Charlie] }

You might also like