How can I truncate a value in an array of objects based on specific criteria?
Let's use the following example:
var items = [
{
name: "CN=arun, hjsdhjashdj,jsdhjsa,kshd",
status: "Present"
}, {
name: "CN=manohar, abcdefghij,111111,2222222",
status: "Present"
}, {
name: "manohar",
status: "Absent"
}]
I want to truncate the value only if it contains "CN=" and update the array accordingly.
The desired updated array should be:
var items = [
{
name: "CN=arun...",
status: "Present"
}, {
name: "CN=manohar...",
status: "Present"
}, {
name: "manohar",
status: "Absent"
}]
To achieve this, I need to check for the presence of "CN=" in each string, truncate at the first comma, add "..." and then update the same array using forEach method.