K
K
klinnov2016-09-27 18:05:35
JavaScript
klinnov, 2016-09-27 18:05:35

How to sort an array using Underscore.js?

Hello!
There are two arrays. Associative.
For example:
1. [ "0" : ["id": 5, "name": "Test"] , "1" : ["id": 6, "name": "Test"], "2" : ["id": 7, "name": "Test"], "3" : ["id": 8, "name": "Test"]]
1. [ "0" : ["id": 5, "name": "Test"] , "1" : ["id": 6, "name": "Test"]]
It is necessary that only those elements that are not in the second remain in the first one.
Subarrays are different. But in all of them there will be an id - by which it is necessary to sort .
Preferably using Underscore.js
_. difference only as I understand it for one-dimensional arrays?
Thank you!
PS. I decided so myself. But don't like

var current_q_ids = underscore.pluck($scope.current_questions, 'id');
                angular.forEach(current_q_ids, function (v, k) {
                    var question = underscore.find($scope.tmp_questions, function (i) {
                        return i.id == v;
                    });
                    $scope.tmp_questions.splice(underscore.indexOf($scope.tmp_questions, question), 1);
                });

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question