1

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

5
  • You what to iterate this array and create a new one with [rateType] values? Commented Oct 26, 2016 at 11:24
  • Can you explain more? What should the new array contain? Commented Oct 26, 2016 at 11:25
  • Use Array.prototype.filter(). Commented Oct 26, 2016 at 11:26
  • I want to create a separate array for rateType and store all rateType values in it Commented Oct 26, 2016 at 11:27
  • i have updated the array. this is my array Commented Oct 26, 2016 at 11:41

1 Answer 1

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!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.