Related Articles

Related Articles

Collect.js except() Method
  • Last Updated : 25 Nov, 2020

The except() method is used to return all items in the given collection except the specified keys.

Syntax:

collect(array).except(key)

Parameters: The collect() method takes one argument that is converted into the collection and then except() method is applied on it. The except() method takes one parameter as key which you want to remove from given collection.

Return Value: This method returns the collection items except the given keys items.

Below example illustrate the except() method in collect.js:



Example 1:

Javascript

filter_none

edit
close

play_arrow

link
brightness_4
code

const collect = require('collect.js');
  
const arr = [2, 4, 5, 6, 8, 9, 10];
  
const collection = collect(arr);
  
const remaining_element = 
    collection.except(5, 7, 9, 10, 12);
  
console.log(remaining_element);

chevron_right


Output:

Collection { items: [ 2, 4, 6, 8 ] }

Example 2:

Javascript

filter_none

edit
close

play_arrow

link
brightness_4
code

const collect = require('collect.js');
  
const arr = ['Geeks', 'GFG', 'GeeksforGeeks', 'Welcome'];
  
const collection = collect(arr);
  
const remaining_element = collection.except('GFG');
  
console.log(remaining_element);

chevron_right


Output:

Collection { items: [ 'Geeks', 'GeeksforGeeks', 'Welcome' ] }

full-stack-img

My Personal Notes arrow_drop_up
Recommended Articles
Page :