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.
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, ...
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> ...
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> ...