I have a array and i want to make different array for different values. this is my array
var data = [{
"rateType": "Fixed",
"interestRateMin": "12.0",
"imageUrl": "\/images\/dyn\/null.jpg",
"financingPercentageMax": "80",
"interestRateMax": "12.0",
"prePaymentCharge": "Nil",
"financingPercentageMin": "60",
"bankName": "Muthoot Finance",
"security": "Pledge of the gold ornaments and coins.",
"repaymentTenureInYears": "0.25",
"age": "35",
"processingFee": "Nil",
"maxLoanAmt": "10000000"
}, {
"rateType": "Floating",
"interestRateMin": "12.5",
"imageUrl": "\/images\/dyn\/94.jpg",
"financingPercentageMax": "90",
"interestRateMax": "12.5",
"prePaymentCharge": "DNA",
"financingPercentageMin": "75",
"bankName": "Federal Bank- Gold loan",
"security": "DNA",
"repaymentTenureInYears": "1",
"age": "35",
"processingFee": "DNA",
"maxLoanAmt": "7500000"
}, {
"rateType": "Floating",
"interestRateMin": "13.0",
"imageUrl": "\/images\/dyn\/155.jpg",
"financingPercentageMax": "80",
"interestRateMax": "13.0",
"prePaymentCharge": "DNA",
"financingPercentageMin": "80",
"bankName": "State Bank of Travancore- Liquid loan",
"security": "Pledge of gold ornaments",
"repaymentTenureInYears": "1",
"age": "35",
"processingFee": "DNA",
"maxLoanAmt": "1000000"
}, {
"rateType": "Floating",
"interestRateMin": "13.25",
"imageUrl": "\/images\/dyn\/151.jpg",
"financingPercentageMax": "80",
"interestRateMax": "13.25",
"prePaymentCharge": "DNA",
"financingPercentageMin": "80",
"bankName": "State Bank Of Hyderabad- Overdraft",
"security": "Pledge of Gold ornaments or Jewellery made of 22 Carat or 18 Carat",
"repaymentTenureInYears": "3",
"age": "35",
"processingFee": "1.10% of the original limit or max Rs 330",
"maxLoanAmt": "1500000"
}, {
"rateType": "Floating",
"interestRateMin": "14.5",
"imageUrl": "\/images\/dyn\/161.jpg",
"financingPercentageMax": "80",
"interestRateMax": "14.5",
"prePaymentCharge": "DNA",
"financingPercentageMin": "80",
"bankName": "Lakshmi Vilas Bank",
"security": "Pledge of gold ornaments",
"repaymentTenureInYears": "1",
"age": "35",
"processingFee": "0.50% of the limit sanctioned, min Rs 100",
"maxLoanAmt": "5000000"
}];
I want to store all rateType in one array. Like this i want to make different array to store other elements. Can someone guide me on this
kukkuz
42.5k6 gold badges65 silver badges103 bronze badges
1 Answer 1
If you want to get an array of the rateTypes (for instance) in the data object, you can do this:
var data=[{rateType:"Fixed",interestRateMin:"12.0",imageUrl:"/images/dyn/null.jpg",financingPercentageMax:"80",interestRateMax:"12.0",prePaymentCharge:"Nil",financingPercentageMin:"60",bankName:"Muthoot Finance",security:"Pledge of the gold ornaments and coins.",repaymentTenureInYears:"0.25",age:"35",processingFee:"Nil",maxLoanAmt:"10000000"},{rateType:"Floating",interestRateMin:"12.5",imageUrl:"/images/dyn/94.jpg",financingPercentageMax:"90",interestRateMax:"12.5",prePaymentCharge:"DNA",financingPercentageMin:"75",bankName:"Federal Bank- Gold loan",security:"DNA",repaymentTenureInYears:"1",age:"35",processingFee:"DNA",maxLoanAmt:"7500000"},{rateType:"Floating",interestRateMin:"13.0",imageUrl:"/images/dyn/155.jpg",financingPercentageMax:"80",interestRateMax:"13.0",prePaymentCharge:"DNA",financingPercentageMin:"80",bankName:"State Bank of Travancore- Liquid loan",security:"Pledge of gold ornaments",repaymentTenureInYears:"1",age:"35",processingFee:"DNA",maxLoanAmt:"1000000"},{rateType:"Floating",interestRateMin:"13.25",imageUrl:"/images/dyn/151.jpg",financingPercentageMax:"80",interestRateMax:"13.25",prePaymentCharge:"DNA",financingPercentageMin:"80",bankName:"State Bank Of Hyderabad- Overdraft",security:"Pledge of Gold ornaments or Jewellery made of 22 Carat or 18 Carat",repaymentTenureInYears:"3",age:"35",processingFee:"1.10% of the original limit or max Rs 330",maxLoanAmt:"1500000"},{rateType:"Floating",interestRateMin:"14.5",imageUrl:"/images/dyn/161.jpg",financingPercentageMax:"80",interestRateMax:"14.5",prePaymentCharge:"DNA",financingPercentageMin:"80",bankName:"Lakshmi Vilas Bank",security:"Pledge of gold ornaments",repaymentTenureInYears:"1",age:"35",processingFee:"0.50% of the limit sanctioned, min Rs 100",maxLoanAmt:"5000000"}];
var result = [];
data.forEach(function(element){
this.push(element.rateType);
}, result);
console.log(result);
I've use the thisArg of a forEach method to create a new array.
Cheers!
answered Oct 26, 2016 at 11:55
kukkuz
42.5k6 gold badges65 silver badges103 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-js
Array.prototype.filter().