# 300+ Top Lodash Framework MCQs and Answers Quiz

## Lodash Framework Multiple Choice Questions

1. To flatten the array to one level deep, use the Lodash.flatten() function.

1. Lodash.pureflatten()
2. Lodash.deepflatten()
3. Lodash.Oneflatten()
4. Lodash.flatten()

Explanation: To flatten the array to one level deep, use the Lodash.flatten() function.

2. The ____ method is used to return a random integer inside the function’s supplied range.

1. _.rand()
2. _.createrandom()
3. _.random()
4. _.randomnumber()

Explanation: The _.random() method is used to return a random integer inside the function’s supplied range.

3. The Lodash ____ method returns a numeric array.

1. _.range()
2. _.limit()
3. _.array()

Explanation: The Lodash _.range() method returns a numeric array.

4. What will be the output of the following code?

```const value = _.range(10);
console.log(value);
```
1. [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ,10]
2. [1, 2, 3, 4, 5, 6, 7, 8, 9 ,10,11]
3. [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]

Answer: C [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]

Explanation: The output will be the range from 0 to 9 which makes the total of 10 numbers, therefore [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ] will be the output.

5. Which of the following method Divides an array into pieces of a certain size?

1. _.chunk(array, size)
2. _.peice(array, size)
3. _.data(array, size)
4. _.divide(array, size)

Explanation: _.chunk(array, size) method Divides an array into pieces of a certain size.

6. Which of the following method Gets rid of all false values in an array?

1. _.del(array):
2. _.remove(array):
3. _.false(array):
4. _.compact(array)

Explanation: _.compact(array) method Gets rid of all false values in an array.

7. Lodash is a ____ library?

1. C++
2. JavaScript
3. Java
4. Python

Explanation: Lodash is a JavaScript library.

8. The ____ function is used to retrieve the first entry of an array.

1. _.one()
2. _.fortharray()
3. _.first()

Explanation: The _.first() function is used to retrieve the first entry of an array.

9. What will be the output of the following code?

```const value = _.range(0, 15, 5);
console.log(value);
```
1. [ 0, 5, 10 ]
2. [ 0, 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 ]
3. [ 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]
4. [ 0, 5, 10,15 ]

Answer: A [ 0, 5, 10 ]

Explanation: Following will be the output: [ 0, 5, 10 ], 15 will not be included in the range.

10. The function is called n times by ____ method.

1. _.repeat()
2. _.times()
3. _.counter().

Explanation: The function is called n times by _.times() method

11. What will be the output of the following code?

```array = [1, 2, 3, 4, 5, 6, 7, 8, 9];
let chunk1 = _.chunk(nums, 2);
console.log( chunk1);
```
1. [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ], [ 7, 8 ], [ 9 ] ]
2. [ 0, 1 ], [ 2, 3 ], [ 4, 5 ], [ 6, 7 ], [ 8,9 ]
3. [ [ 0, 1 ], [ 2, 3 ], [ 4, 5 ], [ 6, 7 ], [ 8,9 ] ]

Answer: A [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ], [ 7, 8 ], [ 9 ] ]

Explanation: The following will be the output: [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ], [ 7, 8 ], [ 9 ] ]

12. _.slice() method takes how many indexes?

1. 1
2. 2
3. 3

Explanation: _.slice() method takes two indexes: starting and ending indexes.

13. In _.slice() method, the starting index is ____.

1. Inclusive
2. Exclusive

Explanation: In _.slice() method, the starting index is inclusive.

14. In _.slice() method, the ending index is ____.

1. Inclusive
2. Exclusive

Explanation: In _.slice() method, the ending index is exclusive.

15. What will be the output of the following code?

```array = [1, 2, 3, 4, 5, 6, 7, 8, 9];
let slice1 = _.slice(nums, 3, 7);
console.log(slice1);
```
1. [3, 4, 5, 6]
2. [3, 4, 5, 6,7]
3. [4, 5, 6,7]
4. [3,4, 5, 6,7]

Explanation: The following will be the output: [4, 5, 6,7].

16. The ____ method is used to shuffle a collection.

1. _.reaarange()
2. _.rotate()
3. _.mix()
4. _.shuffle()

Explanation: The _.shuffle() method is used to shuffle a collection.

17. What are some alternatives to lodash?

1. Underscore.js
2. Ramda
3. Rx.js
4. ALL OF THE ABOVE

Answer: D ALL OF THE ABOVE

Explanation: Following are the alternatives of lodash:

• Underscore.js
• Ramda
• Rx.js

18. Which of the following methods Reduces an array to a single value by applying a function to each element and aggregating the result?

1. _.map()
2. _.reduce()
3. _.filter

Explanation: _.reduce() method Reduces an array to a single value by applying a function to each element and aggregating the result.

19. Which of the following Lodash methods generates an object that organizes array members depending on a provided iterate function?

1. _.group()
2. _.groupby()
3. _.reduce()

Explanation: _.groupby() Lodash methods generate an object that organizes array members depending on a provided iterate function.

20. Which of the following Lodash methods generates a new array by applying a function to each member of the existing array?

1. _.map()
2. _.reduce()
3. _.filter