Question:
How can I cut a String in AngularJs?

Solution

If you want to cut a String in AngularJS, you can try using split() and parts[parts.length - 1]. By using this you can get the last name.


The below code will help you understand:

const names = [

  "Shiloh Match Jolie",

  "Zahara Marley Novel",

  "Pax Dix Bat",

  "Maddox Chivan Jcalie"

];


// Function to extract last names

function getLastNames(names) {

  return names.map(fullName => {

    const parts = fullName.split(' ');

    return parts[parts.length - 1];

  });

}


const lastNames = getLastNames(names);

console.log(lastNames);


Suggested blogs:

>How can I access specific data inside a JSON file on an Angular?

>HTTP request after another but only care about first one in Angular?

>Why am I getting unexpected parent reaction to child button Angular?

>How can I combine multiple HTTP calls in Angular using RxJS?

>Why Ng serve doesn't work in Angulars?

>How to use JSON:API along with Angular/RxJs?

>Why Ng server doesn't work in Angulars?

>How to operate data before return it using Angular16?

>How to Embed Node Red into existing Angular application?

>Why Angular routing with mat-toolbar is not working?

>Update Observable with value from a different Observable in Angular

>P-Dropdown doesn't set Value manually with Reactive Form in Angular

>Why Apex stacked chart bar is not showing in the x-axis in Angular?

>How can I delete the 3rdpartylicenses.txt file in Angular?


Nisha Patel

Nisha Patel

Submit
0 Answers