Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

144
Views
Get last item active name on the list

How can i have the last item on the list where the case it is success?

children: [
   {
    case: "no-success",
    name: "bruno",
    endOffset: 5
   },
   {
    case: "no-success",
    name: "pippo",
    endOffset: 5
   }
   {
    case: "success",
    name: "jo",
    endOffset: 5
   },
   {
    case: "success",
    name: "Matteo",
    endOffset: 5
   },
   {
    case: "np-success",
    name: "Robert",
    endOffset: 5
   }
]

I need to have the item where the name is Matteo.

Example for have the first i do : var foundIdx = this.newListWords[i].children.find(item => item.case === 'success').

about 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Definition:

The find() method returns the FIRST element in the provided array that satisfies the provided testing function. If no values satisfy the testing function, undefined is returned.

You can reverse array:

this.newListWords[i].children.reverse().find(item => item.case === 'success')

Or you can use filter and get last child

const filtered = this.newListWords[i].children.filter(item => item.case === 'success')
const lastFind = filtered[filtered.length-1]
about 4 years ago · Santiago Trujillo Report

0

function lastSuccess(list: any[]): any {
  const SUCCESS_STRING = 'success';
  const [lastItem] = list // Take the list's head
    .filter(o => o.success === SUCCESS_STRING) // Filter for success
    .reverse(); // Reverse the list
  return lastItem;
}
const item = lastSuccess(this.newListWords[i].children);
about 4 years ago · Santiago Trujillo Report

0

    var children = [
       {
        case: "no-success",
        name: "bruno",
        endOffset: 5
       },
       {
        case: "no-success",
        name: "pippo",
        endOffset: 5
       },
       {
        case: "success",
        name: "jo",
        endOffset: 5
       },
       {
        case: "success",
        name: "Matteo",
        endOffset: 5
       },
       {
        case: "np-success",
        name: "Robert",
        endOffset: 5
       }
    ];
    
    function getLastSuccess(children) {
        if (!Array.isArray(children)) {
            return {};
        }
        for (var i = children.length - 1, o; o = children[i]; i--) {
            if (o.case === 'success') {
                return o;
            }
        }
    }
    
    console.log(getLastSuccess(children));

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!