I have an array of objects where I need to find closest lower value from that array based on some value or current value in angular 6, I have already tried but its showing undefined.
app.component.html
<button (click) ="getPrev()">Previous Value</button>
app.component.ts
declare var require: any;
import { Component } from '@angular/core';
import { OnInit } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent{
arrayVal:any;
currentVal : any;
title = 'projectchart';
public array = [{"id":1},{"id":3},{"id":5}];
getPrev(){
this.currentVal = 5;
this.arrayVal= this.array;
let number = this.arrayVal.reverse().find(e => e <= this.currentVal);
console.log(number);
}
}