Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Salesforce
  3. Question
Salesforce

How to convert a list to a list of lists in Javascript?

Asked by Dipesh Bhardwaj May 1, 2023 1.3K views 1 answer
Share

About this question

I'm trying to turn a list into a list of lists. In this case I have a list similar to the following: a = [ 1, 1, 1, 2, 3, 3] and I would like to separate the same items for another list, like: a = [[1, 1, 1] ; [2] ; [3, 3]]
let b = this.a.filter((element, index) => { return this.a.indexOf(element) === index; });

I tried using splice and filter, but without success. I was only able to create a list with different values... b=[1,2,3] Is there any solution?

Your answer

1 Answer

More Salesforce discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest Salesforce Blogs

Guides, tips and career advice on Salesforce from JanBask experts.