0% found this document useful (0 votes)
21 views3 pages

Data Structures Summary

The document provides a summary of four data structures: Array, Set, Map, and Object, detailing their characteristics and operations. Arrays allow duplicate values and maintain order, Sets ensure uniqueness without order, Maps support flexible key types while maintaining insertion order, and Objects use string keys with no guaranteed order. Each structure is suited for different use cases, such as ordered collections, uniqueness, key-value pairs, and simple key-value storage.

Uploaded by

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

Data Structures Summary

The document provides a summary of four data structures: Array, Set, Map, and Object, detailing their characteristics and operations. Arrays allow duplicate values and maintain order, Sets ensure uniqueness without order, Maps support flexible key types while maintaining insertion order, and Objects use string keys with no guaranteed order. Each structure is suited for different use cases, such as ordered collections, uniqueness, key-value pairs, and simple key-value storage.

Uploaded by

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

Data Structures Summary: Array, Set, Map, Object

1. Array:

- A collection of ordered elements, can have duplicates.

- Operations:

- push(), pop(), shift(), unshift()

- forEach(), map(), filter(), find(), sort(), includes(), indexOf(), slice(), splice()

- Note:

- Only one that supports `sort()`.

- Allows duplicate values.

2. Set:

- A collection of unique values (no duplicates), unordered.

- Operations:

- add(value), delete(value), has(value), clear()

- forEach(), size, Array.from(set)

- Note:

- Prevents duplicates automatically.

- Does not maintain order of elements.

3. Map:

- A collection of key-value pairs, keys can be of any type.

- Operations:

- set(key, value), get(key), has(key), delete(key), clear()

- entries(), keys(), values(), size, Array.from(map)


- Note:

- Supports keys of multiple types (unlike `Object` which only supports `string` and `symbol`).

- Maintains insertion order of keys.

- Does not prevent duplicate values (only keys must be unique).

4. Object:

- A collection of key-value pairs, but keys are automatically converted to strings or symbols.

- Operations:

- obj.key = value, obj[key] = value, delete obj[key]

- Object.keys(), Object.values(), Object.entries()

- Note:

- Faster than Map for simple cases.

- Does not support keys of types other than `string` or `symbol`.

- Does not guarantee key ordering like Map.

Comparison:

| Feature | Array | Set | Map | Object |

|---------------------|--------------|----------------|-----------------|------------------|

| Duplicate values? | Yes | No | Yes (in values) | Yes |

| Keys of different types? | No (index only) | No | Yes | No (only strings)|

| Order of elements? | Yes (index) | No | Yes (insertion) | No |

| Suitable for pairs? | No | No | Yes | Yes |

| Direct `sort()`? | Yes | No | No | No |

| Only unique values? | No | Yes | No | No |

| Easy iteration? | Yes (forEach)| Yes | Yes | Yes (for...in) |


Notes:

- `Array`: Ideal for ordered collections where duplicates are allowed.

- `Set`: Use when uniqueness is required and order doesn't matter.

- `Map`: Best for key-value pairs where key types are flexible and order matters.

- `Object`: Ideal for key-value pairs with string keys, optimized for simple use cases.

You might also like