VOOZH about

URL: https://www.geeksforgeeks.org/javascript/collect-js-flip-function/

⇱ Collect.js | flip() function - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Collect.js | flip() function

Last Updated : 11 Jun, 2020

The flip() function swaps the key with its corresponding value. In JavaScript, the array is first converted to a collection and then the function is applied to the collection.


Syntax: 

data.flip()

Parameters: This function does not accept any parameter.

Return Value:  Returns by flipping the collection.
 

Below examples illustrate the flip() function in collect.js
Example 1:  Here in this example, we take a collection and then using the flip() function we flip the key and the item in collection.

Output:

Collection { items: { 'Jhon ': 'name', '-555': 'number' } }

Example 2:

Output:

{ '2546': 'pin', '8715': 'number', '311-Street,US': 'address' }

Reference: https://collect.js.org/api/count.html

Comment
Article Tags: