TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
ahmed elbarbary
NA
1.6k
278.3k
when filter data by using fieldnamefilter variable it give m
Jun 8 2020 5:10 PM
work on angular 7 app I face Issue when filter data using data[0][this.fieldnamefilter] it give me N/A
I filter data by using variable fieldnamefilter
below code is give n/a on this.fieldnamefilter function filter :
contentBody:any[];
fieldnamefilter:any; data is have datatype any[];
console.log("data values : " + this.fieldnamefilter ) //result is data values : onlineURL on console log
// when use data[0][this.fieldnamefilter] it give me N/A
this.contentBody = data.filter(item =>item != data[0][this.fieldnamefilter]);
but If I use it as data[0].onlineURL it working ; //working when use field name direct data[0].onlineURL
this.contentBody = data.filter(item =>item != data[0].onlineURL);
so How to solve this issue ;
Updated post I try :
console.log(this.fieldnamefilter it give me onlineURL
when use field name direct it work but on my case i stored filter name on variable
so how to use variable name on data[0].variable have filter
if you store a field in that variable, you can use it like this:
data[0][this.fieldnamefilter] const data = [{onlineurl: 'asdasd'}, {onlineurl: 'xxxx'}];
const fieldnamefilter = 'onlineurl';
const filteredData = data.filter(entry => entry[fieldnamefilter] === data[0][fieldnamefilter
Reply
Answers (
1
)
button accordion not work when collapse or expand?
How to replace img src in html string in typescript?