Angular with Typescript programming..
this.datalist = Object.data;
if (this.datalist != null) {
this.datalist.forEach(ele => {
ele.fullname = ele.firstname + ' ' + ele.lastname;
this.candidatename=ele.fullname
});
}
firstname = Abhi
lastname = reddy
fullname= Abhi reddy
Indexof:
The location within the calling string to start the search from. It can be any integer between 0 and the length of the string. The default value is 0.
const fruits = ["Banana", "Orange", "Apple", "Mango"];
let index = fruits.indexOf("Apple");
output: 2
ex:1
this.ListData.forEach(ele => {
ele.index = this.ListData.indexOf(ele) + 1;
)}
ex:2
var idDot = name.lastIndexOf(".") + 1;
Splice:
The splice method can be used in Angular applications to manipulate arrays of data. Here's how it works:
array.splice(startIndex, deleteCount, item1, item2, ...);
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
template: `
<button (click)="addItem()">Add Item</button>
<button (click)="removeItem()">Remove Item</button>
<ul>
<li *ngFor="let item of items">{{ item }}</li>
</ul>
`,
})
export class AppComponent {
items: string[] = ['Item 1', 'Item 2', 'Item 3'];
addItem() {
this.items.splice(1, 0, 'New Item'); // Add 'New Item' at index 1
}
removeItem() {
this.items.splice(1, 1); // Remove 1 item at index 1
}
}