example:
var request = require("request");
window.onload = function () {
//credit card
var headers = {
accept: "*/*",
"X-Api-Key": "your api key3",
};
var options = {
url: "https://randommer.io/api/Card?type=visa",
headers: headers,
};
function callback(error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body);
let yes = (JSON.stringify(body));
document.getElementById("output").innerHTML = yes;
}
}
request(options, callback);
};
but then it will come out like this
"{"type":"Visa","date":"2027-01-24T04:50:48.4659778 00:00","fullName":"lolsk semine","cardNumber":"49223456782","cvv":"987}"
something like this i want just only the full name,cardnumber,etc none of
":/
showing. not showing what it is the type, the text cardnumber
i want it to come out like this
"{Visa,27-01,lolsk semine, 49223456782,987}"
and this is my html code
<script src="scriptbr.js"></script>
<h7 id="output"></h7>
and could i divide them into different divisions
and if your wondering i used browserify for require to work in html
i am kinda new to javascript
CodePudding user response:
You can use object destructuring for the jsonObject:
const card = {
type: body.type,
date: body.date,
fullname: body.fullname,
cardNumber : body.cardNumber,
cvv: body.cvv
}
Then stringify to make it a string,
let output = "{${card.type},${card.date},${card.fullname},${cardNumber},${cvv}}";
and then, document.getElementById('output').innerHTML = output;