Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
</body>
</html>
 
var arr = [ 
     { 
       SortTime: 123456, 
       Operation: 'first operator'
     }, {
       SortTime: 4567,
       Operation: Assigning
     }, {
       SortTime: 123456,
       Operation: 'second operator'
     }];
console.log(arr)
var copy = [...arr];
copy.sort(function(a, b) {
    if (a.val.SortTime === b.val.SortTime) {
        return arr.indexOf(a) - arr.indexOf(b);
    } else {
        return a.val.SortTime - b.val.SortTime;
    }
});
console.log(arr)
console.log(copy)
Output

This bin was created anonymously and its free preview time has expired (learn why). — Get a free unrestricted account

Dismiss x
public
Bin info
anonymouspro
0viewers