The values() method is used to return a new collection with the given keys reset to consecutive integers.
Syntax:
collect(array).values(key)
Parameters: The collect() method takes one argument that is converted into the collection and then values() method is applied to it. The values() method holds the key as a parameter.
Return Value: This method returns a new collection with the given keys reset to consecutive integers.
Below example illustrate the values() method in collect.js:
Example 1:
Javascript
const collect = require( 'collect.js' );
const collection = collect([ 'Geeks' ,
'Welcome' , 'GFG' , 'GeeksforGeeks' ]);
const val = collection.values(); console.log(val.all()); |
Output:
[ 'Geeks', 'Welcome', 'GFG', 'GeeksforGeeks' ]
Example 2:
Javascript
const collect = require( 'collect.js' );
let obj = [ {
name: 'Rahul' ,
marks: 88
},
{
name: 'Aditya' ,
marks: 78
},
{
name: 'Abhishek' ,
marks: 87
}
]; const collection = collect(obj); const val = collection.values(); console.log(val.all()); |
Output:
[ { name: 'Rahul', marks: 88 }, { name: 'Aditya', marks: 78 }, { name: 'Abhishek', marks: 87 } ]