'{!cnt}' is a string, so you can put it into an array and loop through it as so.
// Create an array
var contactIds = '{!cnt}'
.replace('[','')
.replace(']','')
.split(',');
// Loop through it
for (var i = 0; i < contactIds.length; i++) {
// Alert the id
alert(contactIds[i]);
}
But all you will get is the the Id. It's best to use JavaScript Remoting in case you need more than the Id.
<apex:page standardController="Account" extensions="testjavascriptextension">
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"/>
<script>
var recordId='{!$CurrentPage.Parameters.id}';
// Check to see if their is an Id to ensure you have an account Id
if (recordId !== '') {
// Create array
var contactIds = '{!cnt}'
.replace('[','')
.replace(']','')
.split(',');
// Loop through it
for (var i = 0; i < contactIds.length; i++) {
// Alert the Id
alert(contactIds[i]);
}
Visualforce.remoting.Manager.invokeAction('testjavascriptextension.getContacts',
recordId,
function(result, event) {
if (event.status) {
console.log(result);
// JavaScript - loop through the contacts
for (var i = 0; i < result.length; i++) {
// Get the Id
console.log(result[i].Id);
// Get the name too
console.log(result[i].Name);
// alert(result[0].Id);
// alert(result[0].Name);
}
// jQuery
$.each(result, function(index, contact) {
// Get the Id
console.log(contact.Id);
// Get the name too
console.log(contact.Name);
// alert(contact.Id);
// alert(contact.Name);
});
} else {
console.log(event.message);
}
}, {
escape: true
});
}
</script>
Controller:
global class testjavascriptextension {
public Account acct{get;set;}
public List<Contact> cnt{get;set;}
public testjavascriptextension(ApexPages.StandardController controller) {
this.acct= (Account)controller.getRecord();
cnt=[select name,id from contact where contact.account.id=:acct.id];
}
@RemoteAction
global static List<Contact> getContacts(String acctId) {
return [select name, id from contact where contact.account.id =:acctId];
}
}