JavaScript Sort the data having combination of letters and digits has value in array of json in javascript

How to sort the array of json data having letters and digits?

JS:

function sortOn(property) {
        return function (a, b) {
            if (a[property] < b[property]) {
                return -1;
            } else if (a[property] > b[property]) {
                return 1;
            } else {
                return 0;
            }
        }
    }

  var data = [{"id":1,name:"text10"},
              {"id":4,"name":"text1"}, {"id":4,"name":"text19"},     {"id":4,"name":"text2"}, {"id":4,"name":"text20"},
               {"id":5,"name":"book"}];
data.sort(sortOn('name'));
console.log(data);// when I print the JSON getting book,text1,text10..

//But I have to want to show the json as book,text1,text2...

Any one can help me how to sort the name thing having both letters and digits

Please find the jsfiddle for reference.

Answer:1

I am trying to write a debounce function in typescript, but am unsure of what type to set a variable that is assigned to setTimeout. My code looks like this: function debounced(func: () => void, ...

I am trying to write a debounce function in typescript, but am unsure of what type to set a variable that is assigned to setTimeout. My code looks like this: function debounced(func: () => void, ...

  1. what type should i make silvally
  2. what type should infj date
  3. what type should i use against fighting
  4. what type should i date
  5. what type should intj date
  6. what type should intp date
  7. what type should i make type null
  8. what type should silvally be
  9. what type should type 9 date
  10. what type should
  11. what should type 2 diabetics eat
  12. what should type 1 diabetics eat
  13. what should type o blood eat
  14. what should type a blood eat
  15. what should type b blood eat
  16. what should type a positive blood eat
  17. what should type ab blood eat
  18. what personality type should i date
  19. what enneagram type should i date
  20. what type dog should i get

Is it possible to manually set the submitted state to true/false in Angular 6? I can markAsPristine and form.reset(), but these don't have an affect on the submitted state... The form lives in a ...

Is it possible to manually set the submitted state to true/false in Angular 6? I can markAsPristine and form.reset(), but these don't have an affect on the submitted state... The form lives in a ...

<button class="user_badge" mat-raised-button color="primary" matBadge="1000" matBadgePosition="after" matBadgeColor="accent" MatBadgeSize="large"> <mat-icon>person</mat-icon> ...

<button class="user_badge" mat-raised-button color="primary" matBadge="1000" matBadgePosition="after" matBadgeColor="accent" MatBadgeSize="large"> <mat-icon>person</mat-icon> ...

  1. angular material custom theme
  2. angular material custom palette
  3. angular material custom validator
  4. angular material custom icons
  5. angular material custom theme not working
  6. angular material custom component
  7. angular material custom theme tutorial
  8. angular material custom tooltip
  9. angular material custom colors
  10. angular material custom sort
  11. angular material custom stepper
  12. angular material custom pagination
  13. angular material custom sort function
  14. angular material custom button color
  15. angular material custom palette generator
  16. angular material custom styles
  17. angular material custom filter predicate
  18. angular material custom dropdown
  19. angular material custom elements
  20. angular material custom dialog

I'm trying to get a number of days of selected year of selected month by javascript. But it has been giving me a NaN value in result. What should i do to solve this issue ? Thanks. <script> ...

I'm trying to get a number of days of selected year of selected month by javascript. But it has been giving me a NaN value in result. What should i do to solve this issue ? Thanks. <script> ...

  1. return value javascript function
  2. return value javascript to html
  3. return value javascript to php
  4. return value javascript onclick function
  5. return value javascript function html
  6. return value javascript ajax
  7. return value javascript constructor
  8. return value javascript async
  9. return value javascript alert
  10. return value javascript class
  11. return value javascript recursion
  12. return value javascript loop
  13. return value javascript data
  14. return value javascript push
  15. return value javascript void
  16. return value javascript null
  17. return value javascript in settimeout
  18. return value javascript condition
  19. return javascript value to c#
  20. return promise value javascript